#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
import sys


sk = socket.socket()
print(sk)

address = ('127.0.0.1',8000)
sk.connect(address)


while True:
    inp = input('>>>')
    if inp == 'exit':
        break
    sk.sendall(bytes(str(inp),'utf8'))
    result_len = int(str(sk.recv(1024),'utf8'))

    #解决severy的粘包
    sk.sendall(bytes(str('ok'),'utf8'))


    print(result_len)
    data=bytes()
    while len(data) != result_len:
        recv = sk.recv(1024)
        data+=recv
    print(str(data,'gbk'))#为什么gbk解码？ 因为windows返回的默认是gbk的bytes类型

sk.close()